import java.util.*;

/**
 * A {@link LocalServer} comprised of multiple delegate servers.
 */
abstract class MultiLocalServer extends LocalServer {

  private final Collection<LocalServer> delegates = new HashSet<LocalServer>();

  protected boolean showIP() {return true;}
  
  protected final void addLocalServer(LocalServer server) {
    if (server == this) {
      throw new IllegalArgumentException("Cannot add this");
    }
    delegates.add(server);
  }

  Handler[] getHandlers() {
    List<Handler> lst = new ArrayList<Handler>();
    for (LocalServer s : delegates) {
      for (Handler h : s.getHandlers()) {
        lst.add(h);
      }
    }
    return (Handler[])lst.toArray(new Handler[lst.size()]);
  }

  protected void processArgs(Iterable<String> args) {
    for (LocalServer s : delegates) {
      s.processArgs(args);
    }
  }
}